package com.example.ballviewdemo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class BallView extends View {

    private int cx;
    private int cy;


    public BallView(Context context, AttributeSet attrs) {
        super(context, attrs);
        cx = cy = 50;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        canvas.drawCircle(cx, cy, 40, paint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        cx = (int) event.getX();
        cy = (int) event.getY();
        invalidate();
        return super.onTouchEvent(event);
    }
}
